<?php


if (isset($_GET['nom_salle']) && isset($_GET['nom_spectacle']) && isset($_GET['code_postal'])) {
	$nomsalle = sql_protect(html_escape($_GET['nom_salle']));
	$nomspectacle = sql_protect(html_escape($_GET['nom_spectacle']));
	$codepostal = $_GET['code_postal'];
	}

if (isset($_POST['d_j']) && isset($_POST['d_m']) && isset($_POST['d_a']) && isset($_POST['h_h']) && isset($_POST['h_m'])) {
	$d_j = $_POST['d_j'];
	$d_m = $_POST['d_m'];
	$d_a = $_POST['d_a'];
	$h_h = $_POST['h_h'];
	$h_m = $_POST['h_m'];
	
	$result = SGBD::query(
			"INSERT INTO creneau (pkcreneau, debut, nomsalle, cpcommune, nomspectacle)
			VALUES (nextval('pkcreneau'), '$d_a-$d_m-$d_j $h_h:$h_m:00', '$nomsalle', '$codepostal', '$nomspectacle'); "
			);
	if(!$result){
	header("Location: index.php?page=admin_representations_creneaux&nom_salle=$nomsalle&nom_spectacle=$nomspectacle&code_postal=$codepostal");
	
	}
		
	else {
		header("Location: index.php?page=admin_representations");
	}

}




	$template->setTemplateFile('show_infos_affectation_creneaux','tpl/show_infos_affectation_creneaux.tpl');
	$template->setTemplateFile('center','tpl/center.tpl');
	$template->parseTemplate('center',"CENTER_CONTENT",$template->getTemplate('show_infos_affectation_creneaux'));

?>
